package com.ahstu.learning.player;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ahstu.learning.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by xuning on 2016/7/28.
 */
public class CommentActivity extends Activity {
    ImageView comment_backbutton;
    TextView comment_fabu;
    EditText comment_edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comment_activity);
        init();
    }

    void init() {
        comment_edit = (EditText) findViewById(R.id.comment_edit);
        comment_edit.setFocusable(true);
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                //Toast.makeText(MainActivity.this, "show", Toast.LENGTH_SHORT).show();
            }
        }, 500);  //在一秒后打开
        comment_edit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
        comment_backbutton = (ImageView) findViewById(R.id.comment_backbutton);
        comment_backbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("comment", "");
                setResult(0, intent);
                finish();
            }
        });

        comment_fabu = (TextView) findViewById(R.id.comment_fabu);
        comment_fabu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (comment_edit.getText().toString().equals("")) {
                    Toast.makeText(CommentActivity.this, "发布内容不能为空", Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent();
                    intent.putExtra("comment", comment_edit.getText().toString());
                    //Toast.makeText(CommentActivity.this,comment_edit.getText(), Toast.LENGTH_SHORT).show();
                    setResult(0, intent);
                    finish();
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("comment", "");
        setResult(0, intent);
        finish();
    }
}
